package soccer.model.matchesDetail;

import java.util.List;
import soccer.model.matches.MatchConstant;
import soccer.utility.db.dbUtility;

public class MatchesDetailDAOImpl {
    public void enterMatchDetail(MatchesDetail md){
    	StringBuffer query1 = new StringBuffer();
    
    	
    	
    }
    public void enterPlayedPlayerOfMatchDetail(){
    	
    	
    }
    
    public void enterGoalsOfMatchDetail(){}
    
    
    public List getHomePlayerOfMatchDetail(MatchesDetail md){
    	List homePlayers = getPlayedPlayerOfMatchDetail(md,MatchConstant.HOME_TEAM_TYPE);
    	return homePlayers;
    }
    public List getAwayPlayerOfMatchDetail(MatchesDetail md){
    	List awayPlayers = getPlayedPlayerOfMatchDetail(md,MatchConstant.AWAY_TEAM_TYPE);
    	return awayPlayers;
    }
   
    public List getPlayedPlayerOfMatchDetail(MatchesDetail md , int type){
    	StringBuffer query = new StringBuffer();
    	query.append("SELECT * FROM matchdetail md, playersofmatch pom ,player p");
    	query.append(" WHERE md.matchDetailId = pom.matchDetailId AND pom.playerId = p.playerId");
    	query.append(" AND md.matchDetailId = ? AND pom.type = ?");
    	
    	Object[] params = new Object[]{md.getMatchDetailId() ,type};
    	dbUtility db = dbUtility.getInstance();
    	@SuppressWarnings("rawtypes")
		List players = db.execute(query.toString(), params);
    	return players;
    }
    public List getHomeGoalsOfMatchDetail(MatchesDetail md){
    	StringBuffer query  = new StringBuffer();
    	query.append("SELECT * FROM matchdetail md , player p , goal g ");
    	query.append(" WHERE md.matchDetailId = g.matchDetailId AND g.golScorer = p.playerId AND type = 1");
    	query.append(" AND md.matchDetailId = ?");
    	
    	Object[] params = new Object[]{md.getMatchDetailId()};
    	dbUtility db = dbUtility.getInstance();
    	List players = db.execute(query.toString(), params);
    	return players;
    }
    public List getAwayGoalsOfMatchDetail (MatchesDetail md){
    	StringBuffer query  = new StringBuffer();
    	query.append("SELECT * FROM matchdetail md , player p , goal g ");
    	query.append(" WHERE md.matchDetailId = g.matchDetailId AND g.golScorer = p.playerId  AND type = 0");
    	query.append(" AND md.matchDetailId = ?");
    	
    	Object[] params = new Object[]{md.getMatchDetailId()};
    	dbUtility db = dbUtility.getInstance();
    	List players = db.execute(query.toString(), params);
    	return players;
    }
    public List getMatchDetailOfMatch(int matchId){
    	List matchDetail;
    	StringBuffer query = new StringBuffer();
    	query.append("SELECT * FROM matchDetail ");
    	query.append(" WHERE matchId =  ");
    	query.append(matchId);
    	
    	dbUtility db = dbUtility.getInstance();
        matchDetail = db.execute(query.toString());
        return matchDetail;
    }
}
